package com.caigou.modules.forum.ui.comment

import androidx.activity.viewModels
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.caigou.comm.base.bean.AppBackgroundInfo
import com.caigou.comm.base.constants.AppConstants
import com.caigou.comm.base.constants.RouterPath
import com.caigou.comm.base.container.BaseReplyActivity
import com.caigou.comm.base.ext.observe
import com.caigou.modules.forum.bean.PostDetailBean
import com.caigou.modules.forum.viewmodel.PostViewModel
import dagger.hilt.android.AndroidEntryPoint
import java.io.File

/**
 * @author #Suyghur.
 * Created on 2021/12/03
 */
@Route(path = RouterPath.Forum.PAGE_POST_REPLY)
@AndroidEntryPoint
class PostReplyActivity : BaseReplyActivity() {

    private val postViewModel: PostViewModel by viewModels()

    @Autowired(name = AppConstants.POST_DETAIL_BEAN)
    lateinit var postDetailBean: PostDetailBean

    override fun initView() {
        super.initView()
        binding.replyBtnSubmit.setOnClickListener {
            val content = binding.replyEtContent.text.toString()
            val files: MutableList<File> = mutableListOf()
            urls.forEach {
                files.add(File(it))
            }
            postViewModel.setPostReply(
                content, files, AppBackgroundInfo.instance.userBean!!.userId,
                postDetailBean.userId, postDetailBean.id
            )
        }
    }

    override fun observeViewModel() {
        observe(postViewModel.postReplyLiveData, ::handleSetReply)
    }
}